Component({
  properties: {
    avatarUrl: String,
    username: String,
    description: String
  },
  methods: {
    savePoster() {
      const query = wx.createSelectorQuery().in(this);
      query.select('#posterSnapshot').node().exec(res => {
        const node = res[0].node;
        node.takeSnapshot({
          type: 'arraybuffer',
          format: 'png',
          success: (res) => {
            const fs = wx.getFileSystemManager();
            const filePath = `${wx.env.USER_DATA_PATH}/poster.png`;
            fs.writeFileSync(filePath, res.data, 'binary');
            wx.saveImageToPhotosAlbum({
              filePath,
              success: () => {
                wx.showToast({ title: '海报已保存到相册' });
              },
              fail: err => {
                wx.showToast({ title: '保存失败', icon: 'none' });
                console.error('保存失败', err);
              }
            });
          },
          fail: (err) => {
            wx.showToast({ title: '生成海报失败', icon: 'none' });
            console.error('生成海报失败', err);
          }
        });
      });
    }
  }
});